﻿using System;
using System.ComponentModel.Composition;
using System.Drawing;
using System.Windows.Forms;

namespace PefStudio.Windows
{
    [Export(MainWindow.MainStatusBarContract, typeof(IStatusBarItem))]
    public sealed class StatusLabel : ToolStripStatusLabel, IStatusBarItem
    {
        public StatusLabel()
        {
            Spring = true;
            TextAlign = ContentAlignment.MiddleLeft;
        }

        public string ID 
        {
            get { return "MessageLabel"; }
        }

        public double Index
        {
            get { return 0.0; }
        }

        public string InsertRelativeToID
        {
            get { return string.Empty; }
        }

        public bool BeforeRelativeID
        {
            get { return false; }
        }

        public bool HasSeparator
        {
            get { return false; }
        }

        public void SetMessage(string message, bool highlighted)
        {
            Action setMessageAction = delegate
                                          {
                                              if (highlighted)
                                              {
                                                  BackColor = SystemColors.Highlight;
                                                  ForeColor = SystemColors.HighlightText;
                                              }
                                              else
                                              {
                                                  BackColor = SystemColors.Control;
                                                  ForeColor = SystemColors.ControlText;
                                              }
                                              Text = message;
                                          };
            setMessageAction();
        }
    }
}
